<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			var msgs=[]
			function fun2(){
				var name=document.getElementById("userName").value
				var word=document.getElementById("word").value
				var msg=`[${name}]说：${word}`
				msgs.unshift(msg)
				if(msgs.length>10){
					msgs.pop()
				}
				
				document.getElementById("words").value=msgs.join("\n")
			}
			function fun1(){
				document.getElementById("userName").value=""
				document.getElementById("word").value=""
				document.getElementById("words").value=""
				msgs=[] //msgs.length = 0; 清空数组
				
			}
		</script>
	</head>
	<body>
		姓名：<input type="text"  id="userName"  />
		<br>
		留言：<textarea rows="3" cols="40" id="word"></textarea>
		<br>
		 <button onclick="fun1()">重置</button>
		 <button onclick="fun2()">留言</button><hr >
		 <textarea rows="10" cols="60" id="words"></textarea>
		 
	</body>
</html>
